package xj.util.gui;

import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

public class ResourceManager {

  private ResourceBundle resources;

  public ResourceManager(String name) {
    this(name, null);
  }

  public ResourceManager(String name, Locale locale) {
    if (locale == null) {
      locale = Locale.getDefault();
    }
    try {
      resources = ResourceBundle.getBundle(name, locale);
    } catch (MissingResourceException mre) {
      System.err.println("Resources for " + name + "_" + locale + " not found");
      locale = Locale.getDefault();
      resources = ResourceBundle.getBundle(name, locale);
      //System.exit(1);
    }
  }

  public String getResourceString(String nm) {
    String str;
    try {
      str = resources.getString(nm);
    } catch (MissingResourceException mre) {
      str = null;
    }
    return str;
  }

}
